﻿using RMMvcApplication.BusinessLogic;
using RMMvcApplication.BusinessLogic.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using Tools.BusinessLogic.Service;
using RMMvcApplication.Model;

namespace RMMvcApplication.Controllers
{
    public class HomeController : Controller
    {
        INewsService _newsService;

        public HomeController()
        {
            _newsService = ServiceNinjectConfig.kernel.Get<INewsService>();
        }

        //public HomeController(INewsService newsService)
        //{
        //    _newsService = newsService ?? ServiceNinjectConfig.kernel.Get<INewsService>();
        //}


        public ActionResult Index()
        {
            return View();
        }

        public ActionResult News()
        {
            return View(_newsService.GetAll());
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(News news)
        {
            _newsService.Add(news);
            _newsService.Save();
            return RedirectToAction("News");
            //return View(news);
        }
    }
}
